package com.hk.web.controller.api;


import com.hk.commons.JsonResult;
import com.hk.commons.ProcessAPI;
import com.hk.commons.enums.ArticleType;
import com.hk.commons.enums.OperationEvent;
import com.hk.web.controller.Routes;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created by Antinomy on 17/6/9.
 */
@RestController
@Api(value = "类型说明", description = "类型说明")
public class OptionDetailsAPIController {

    @ApiOperation(value = "查看文章类型", notes = "查看文章类型", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @RequestMapping(value = Routes.API_OPTION_DETAILS_ARTICLE_TYPE, method = RequestMethod.GET)
    @ResponseBody
    public JsonResult activityType(HttpServletRequest request) {
        ProcessAPI api = (jsonResult, validate) -> {

            ArrayList result = new ArrayList();

            for(ArticleType type :ArticleType.values()){
                HashMap item = new HashMap();
                item.put("name",type);
                item.put("value",type.getValue());
                item.put("code",type.getCode());
                result.add(item);
            }

            jsonResult.result = result;
            jsonResult.size = (long) result.size();
        };

        return api.process(request);
    }

    @ApiOperation(value = "查看操作日志类型", notes = "查看操作日志类型", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @RequestMapping(value = Routes.API_OPTION_DETAILS_OPERATION_EVENT, method = RequestMethod.GET)
    @ResponseBody
    public JsonResult operationEvent(HttpServletRequest request) {
        ProcessAPI api = (jsonResult, validate) -> {

            ArrayList result = new ArrayList();

            for(OperationEvent type :OperationEvent.values()){
                HashMap item = new HashMap();
                item.put("event",type);
                item.put("name",type.getName());
                item.put("service",type.getService());
                item.put("menuLv1",type.getMenuLv1());
                item.put("menuLv2",type.getMenuLv2());
                item.put("button",type.getButton());
                item.put("descTemple",type.getDescTemplate());
                result.add(item);
            }

            jsonResult.result = result;
            jsonResult.size = (long) result.size();
        };

        return api.process(request);
    }


}
